package org.hhchat.leetcode.tree;

import org.hhchat.leetcode.dataStruct.TreeNode;

/**
 * https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/description/
 */
public class code108_easy {
    static class Solution {
        public TreeNode sortedArrayToBST(int[] nums) {
            if(nums==null||nums.length==0){
                return null;
            }
            TreeNode root = helper(nums, 0, nums.length - 1);
            return root;
        }
        //二分搜索
        public TreeNode helper(int[] nums, int low,int high){
            if(low>high){
                return null;
            }
            int mid = (low+high)/2;
            TreeNode root = new TreeNode(nums[mid]);
            root.left = helper(nums,low,mid-1);
            root.right = helper(nums,mid+1,high);
            return root;
        }
    }


    public static void main(String[] args){

    }
}
